//
//  HEServerCommentCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/11.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEServerCommentCell.h"
#import "HDRatingStarView.h"

@interface HEServerCommentCell ()

@property (strong, nonatomic) UIImageView *userHeadImg;
@property (strong, nonatomic) UILabel *nameLb;
@property (strong, nonatomic) UILabel *timeLb;

@property (nonatomic, strong) HDRatingStarView *startView;
@property (nonatomic, strong) UILabel *cotentLb;

@end

@implementation HEServerCommentCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        // Fix the bug in iOS7 - initial constraints warning
        self.contentView.bounds = [UIScreen mainScreen].bounds;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.backgroundColor = KWhiteColor;
        self.qmui_borderPosition = QMUIViewBorderPositionBottom;
        self.qmui_borderColor = KHexColor(@"F5F5F5");
        
        [self initUI];
        [self setpData];
    }
    return self;
}

- (void)initUI {
    
    _userHeadImg = [[UIImageView alloc] init];
    _userHeadImg.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:_userHeadImg];
    
    _nameLb = [[UILabel alloc] init];
    _nameLb.font = DYFont(16);
    [self.contentView addSubview:_nameLb];
    
    _timeLb = [[UILabel alloc] init];
    _timeLb.font = DYFont(14);
    _timeLb.textColor = KHexColor(@"757575");
    [self.contentView addSubview:_timeLb];
    
    [_userHeadImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.width.height.mas_equalTo(50);
        make.left.equalTo(self.contentView).mas_offset(15);
    }];
    
    [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_userHeadImg);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-15);
    }];
    [_timeLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    [_nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_userHeadImg);
        make.left.equalTo(_userHeadImg.mas_right).mas_offset(5);
        make.right.equalTo(_timeLb.mas_left).mas_offset(-5);
        make.height.mas_offset(15);
     }];
    [_timeLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    [_nameLb setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
}

- (void)setpData {
     
    _userHeadImg.layer.masksToBounds = YES;
    _userHeadImg.layer.cornerRadius = 25;

    // 星星评分
    _startView = [[HDRatingStarView alloc] init];
    _startView.defaultColor = KHexColor(@"CDCDCD");
    _startView.renderColor = KHexColor(@"F67605");
    _startView.allowTouchToSelectScore = NO;
    _startView.score = 0;
    _startView.starWidth = 15;
    _startView.starImage = IMAGE_NAMED(@"rating_sel");
    [self.contentView addSubview:_startView];
   
    // 评论
    _cotentLb = [UILabel new];
    _cotentLb.font = DYFont(15);
    _cotentLb.numberOfLines = 0;
    _cotentLb.textColor = CNavDargGrayColor;
    [self.contentView addSubview:_cotentLb];
    
    // 可去掉
    _cotentLb.preferredMaxLayoutWidth = KScreenWidth - 20 - 50;
    [_cotentLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
    
    [_startView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(_nameLb.mas_bottom).mas_offset(5);
      make.left.equalTo(_nameLb.mas_left);
      make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
      make.height.mas_greaterThanOrEqualTo(15);
    }];

    [_cotentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_startView.mas_bottom).mas_offset(10);
        make.left.equalTo(_nameLb.mas_left);
        make.right.equalTo(self.contentView.mas_right).mas_offset(-10);
        make.bottom.mas_equalTo(self.contentView).offset(-10);
    }];
}

- (void)setModel:(HEServerCommentModel *)model {
    
    _model = model;
    [_userHeadImg sd_setImageWithURL:[NSURL URLWithString:model.member.avatar] placeholderImage:IMAGE_NAMED(@"noImage")];

    _startView.score = model.score;
    _nameLb.text = model.member.realname;
    _cotentLb.text = model.content;
    _timeLb.text = model.KcreateDate; 
}

@end

